<<<<<<< HEAD
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render,render_to_response
from forms import UserForm
from django.http import HttpResponse
from .models import User
import os
import json

# Create your views here.
def register(request):
    if request.method == 'POST':
        uf = UserForm(request.POST,request.FILES)
        if uf.is_valid():
            headImg = uf.cleaned_data['headImg']
            #这里写入数据库
            user = User()
            user.headImg = headImg
            user.save()

            return HttpResponse('upload ok!')
    else:
        uf = UserForm()
    return render_to_response('index.html',{'uf':'uf'})

#//ajax上传
def scene_update_view(request):
    if request.method == "POST":
            name = request.POST.get('name')
            status = 0
            result = "Error!"
            return HttpResponse(json.dumps({
                "status": status,
                "result": result
            }))




def mgmt_files(request): #列出树形目录，上传文件页面
    if request.method == 'POST':
        path_root = "D:\\py\\ITFiles" #上传文件的主目录
        myFile =request.FILES.get("file", None)    # 获取上传的文件，如果没有文件，则默认为None
        if not myFile:
            dstatus = "请选择需要上传的文件!"
        else:
            path_ostype = os.path.join(path_root,request.POST.get("ostype"))
            path_dst_file = os.path.join(path_ostype,myFile.name)
            # print path_dst_file
            if os.path.isfile(path_dst_file):
                dstatus = "%s 已存在!"%(myFile.name)
            else:
                destination = open(path_dst_file,'wb+')    # 打开特定的文件进行二进制的写操作
                for chunk in myFile.chunks():      # 分块写入文件
                    destination.write(chunk)
                destination.close()
                dstatus = "%s 上传成功!"%(myFile.name)
        return HttpResponse(str(dstatus))

    return render(request,'sinfors/mgmt_files.html')
=======
from django.shortcuts import render,HttpResponse

# Create your views here.
def index(request):
    return render(request,'index.html')
>>>>>>> a363e446fec50a54a0f5ae068d446f085db515fa
